package com.zyf.wjy.controller;

import com.zyf.wjy.entity.User;
import com.zyf.wjy.service.NewsService;
import com.zyf.wjy.service.ProductService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 农场展示控制器
 */
@Controller
@RequestMapping("/farm")
public class FarmController {
    
    @Autowired
    private NewsService newsService;
    
    @Autowired
    private ProductService productService;
    
    /**
     * 农场展示页面
     */
    @GetMapping("/display")
    public String display(HttpSession session, Model model) {
        User currentUser = (User) session.getAttribute("currentUser");
        model.addAttribute("currentUser", currentUser);
        
        // 获取最新公告
        model.addAttribute("newsList", newsService.findPublished());
        
        // 获取优质农产品
        model.addAttribute("productList", productService.findAll());
        
        return "farm/display";
    }
}

